package com.iccct.cloud.commons.result;

import java.util.Objects;

/**
 * @author iccct (taowutt1@gmail.com)
 * @since 2021-11-08  14:10
 */
public class Response<T> {
    private static final long serialVersionUId = 1L;
    private Integer code;
    private String message;
    private T data;

    public Response(String message, Integer code) {
        this.code = code;
        this.message = message;
    }

    public Response(T data, String message) {
        this.data = data;
        this.message = message;
    }

    public Response(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return this.code;
    }

    public String getMessage() {
        return this.message;
    }

    public T getData() {
        return this.data;
    }

    public void setCode(final Integer code) {
        this.code = code;
    }

    public void setMessage(final String message) {
        this.message = message;
    }

    public void setData(final T data) {
        this.data = data;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Response<?> response = (Response<?>) o;
        return Objects.equals(code, response.code) && Objects.equals(message, response.message) && Objects.equals(data, response.data);
    }

    @Override
    public int hashCode() {
        return Objects.hash(code, message, data);
    }

    @Override
    public String toString() {
        return "Response{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }

    public Response() {
    }

    public Response(final Integer code, final String message, final T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
}
